package com.ymatou.iapi.userservice.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.BindEmailBean;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.service.BindEmailCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.TestDataManager;
/**
*绑定邮箱Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_BindEmail{
	private static BindEmailBean BindEmailBean;
	private static BindEmailCall BindEmailCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("绑定邮箱");
	}

	@Before
	public void caseUp() {
		BindEmailBean=new BindEmailBean();
		BindEmailCall=new BindEmailCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(BindEmailCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BindEmail_001() {
		Logger.start(true,"绑定邮箱,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			
			BindEmailBean.setEmail(TestDataManager.getEmail());
			BindEmailBean.setUserId(uid);
			BindEmailCall.setData(BindEmailBean);
			BindEmailCall.callService();			
			Logger.verifyEquals("true", BindEmailCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", BindEmailCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.comment("验证Userinfo");
			Userinfo ui = new JUserWapper().selectUserinfoByUid(uid).get(0);
			Logger.verifyEquals(BindEmailBean.getEmail(), ui.getLoginMail(), "验证mail");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BindEmail_002() {
		Logger.start(false,"重复绑定邮箱,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			
			BindEmailBean.setEmail(TestDataManager.getEmail());
			BindEmailBean.setUserId(uid);
			BindEmailCall.setData(BindEmailBean);
			BindEmailCall.callService();
			BindEmailCall.callService();
			Logger.verifyEquals("true", BindEmailCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", BindEmailCall.getString("ResponseCode"), "验证ResponseCode");
		//	Logger.verifyIsContains("邮箱已被使用", BindEmailCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BindEmail_003() {
		Logger.start(false,"邮箱已经绑定,失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			
			CreateUserReq cur2 = new CreateUserReq();
			cur2 = JUserCallService.initCreateUserBean(cur2);
			Integer uid2 = JUserCallService.createUserCall(cur2);
			
			BindEmailBean.setEmail(cur2.getMail());
			BindEmailBean.setUserId(uid);
			BindEmailCall.setData(BindEmailBean);
			BindEmailCall.callService();
			Logger.verifyEquals("false", BindEmailCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100006", BindEmailCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("邮箱已被使用", BindEmailCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BindEmail_004() {
		Logger.start(false,"不输入userid,失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			
			BindEmailBean.setEmail(TestDataManager.getEmail());
//			BindEmailBean.setUserId(uid);
			BindEmailCall.setData(BindEmailBean);
			BindEmailCall.callService();
			Logger.verifyEquals("false", BindEmailCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", BindEmailCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("UserId 未提供", BindEmailCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BindEmail_005() {
		Logger.start(false,"不输入email,失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			
//			BindEmailBean.setEmail(TestDataManager.getEmail());
			BindEmailBean.setUserId(uid);
			BindEmailCall.setData(BindEmailBean);
			BindEmailCall.callService();
			Logger.verifyEquals("false", BindEmailCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", BindEmailCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("Email 未提供", BindEmailCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BindEmail_006() {
		Logger.start(false,"用户已绑定邮箱,绑定后更新邮箱");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
//			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			
			BindEmailBean.setEmail(TestDataManager.getEmail());
			BindEmailBean.setUserId(uid);
			BindEmailCall.setData(BindEmailBean);
			BindEmailCall.callService();			
			Logger.verifyEquals("true", BindEmailCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", BindEmailCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.comment("验证Userinfo");
			Userinfo ui = new JUserWapper().selectUserinfoByUid(uid).get(0);
			Logger.verifyEquals(BindEmailBean.getEmail(), ui.getLoginMail(), "验证mail");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}